package com.skygrass.caesar.consumer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController()
@RefreshScope
public class ConsumerController
{
	@Autowired
	RestTemplate restTemplate;

	@Autowired
	LoadBalancerClient loadBalancerClient;

	@Value("${testpro}")
	private String testpro;

	@GetMapping("/hello")
	//	@HystrixCommand(fallbackMethod = "helloConsumerFallback")
	//	@Hystrix(fallbackHandler = ConsumerControllerFallbackHandle.class)
	//	@com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand
	public String helloConsumer()
	{
		//		String serviceId = "caesar-provider";
		//
		//		//		ServiceInstance serviceInstance = loadBalancerClient.choose(serviceId);
		//		//		System.out.println(
		//		//				serviceInstance.getServiceId() + ":" + serviceInstance.getHost() + ":" + serviceInstance.getPort());
		//
		//		return restTemplate.getForEntity("http://" + serviceId + "/book/1", String.class).getBody();
		//		HystrixCommand<String> commond = new HelloCommand(restTemplate);
		//				return commond.execute();

		return testpro;
	}

	public String helloConsumerFallback()
	{

		return "now fallback";
	}
}
